################################################################################
  #
  # bw.tcl
  #
  # Description:
  # This script determine the load to use while running "true random"
  # frame sizes in SmartFlow to achieve an average effective load of
  # "desired_load" (specified in the code).
  #
  # Inputs:
  # None
  #
  # Outputs:
  # The load to use
  #
  # Author: Jim Dancho
  #
  # Created: 21 May 2002
  #
  # Last Edited 21 May 2002
  #
  #
  ################################################################################
  
  
  ###################
  # General Variables
  ###################
  
  set TRUE [ expr 1 == 1 ]
  set FALSE [ expr 1 == 2 ]
  set ON $TRUE
  set OFF $FALSE
  set EXISTS $TRUE
  
  
  ################
  # get_user_input
  ################
  
  proc get_user_input { string min max default zero_illegal decimals_illegal} {
   global TRUE FALSE
  
   set response_needed $TRUE
   while { $response_needed } {
   puts $string
   set response [gets stdin]
   set response_needed $FALSE
  
   if { $response == "" } {
   set response $default
   }
  
   if { $response < $min } {
   puts "Response cannot be less than $min"
   set response ""
   set response_needed $TRUE
   } elseif { $response > $max } {
   puts "Response cannot be greater than $max"
   set response ""
   set response_needed $TRUE
   }
   if { ($zero_illegal) && ($response == 0) } {
   puts "Response cannot be zero"
   set response ""
   set response_needed $TRUE
   }
   if { $decimals_illegal } {
   if { $response != [expr round($response)]} {
   puts "Response must be an integer"
   set response ""
   set response_needed $TRUE
   }
   }
   }
  
   return $response
  }
  
  
  
  
  #######################
  # User defined variables
  ########################
  
  # get_user_input string min max default zero_illegal decimal_illegal
  set string "Please enter the desired load \[50\]: "
  set desired_load [get_user_input $string 0 100 50 $TRUE $FALSE]
  
  # frame sizes used
  set string "Please enter the low limit of the frame sizes \[64\]: "
  set min_frame [get_user_input $string 64 1518 64 $TRUE $TRUE]
  
  set string "Please enter the high limit of the frame sizes \[1518\]: "
  set max_frame [get_user_input $string $min_frame 1518 1518 $TRUE $TRUE]
  
  # convert load to a decimal
  set desired_load [expr $desired_load / 100.0]
  
  set preamble 8
  set min_ifg 12
  
  
  proc needed_ifg {frame_sz load} {
   global preamble min_ifg
   set frame_bits [expr $frame_sz + $preamble]
   return [expr (($frame_bits + $min_ifg) / $load) - $frame_bits]
  }
  
  
  set avg_frame [expr ($min_frame + $max_frame) / 2]
  set bits [needed_ifg $avg_frame $desired_load]
  set frame_bits [expr $max_frame + $preamble]
  set actual_load [expr ($max_frame + $min_ifg) / ($max_frame + $bits)]
  
  
  puts -nonewline "To achieve an average bandwidth of [expr 100 *$desired_load]%"
  puts " while varying frame sizes between"
  puts "$min_frame and $max_frame, use a load of [expr 100 * $actual_load]%."
  puts "To achieve this set the IFG to $bits"

